#include "QNetWork.h"
//#include"mainwindow.h"


/**
NetworkManagers::NetworkManagers(){
    manager = new QNetworkAccessManager(this);
}
void NetworkManagers::get(const QUrl &url){
    QNetworkRequest request(url);
    QNetworkReply *reply = manager->get(request);
    connect(reply, &QNetworkReply::finished, this, &NetworkManagers::onFinished);
}

void NetworkManagers::onFinished()
{
   /**
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
    if (reply->error() == QNetworkReply::NoError) {

        QByteArray responseDate = reply->readAll();

        qDebug() << "replay = "<<responseDate;

        QString responseString = QString::fromUtf8(responseDate);
        QJsonDocument doc = QJsonDocument::fromJson(responseDate);
        if (!doc.isNull() && doc.isObject()) {

             QJsonObject roots = doc.object();
             QJsonArray resultsArr = roots["results"].toArray();

             qDebug() << "resultArr = "<<resultsArr;
                for(const QJsonValue &value:resultsArr)
                {
                    if(value.isObject()){
                        QJsonObject obj = value.toObject();
                         last_update = obj["last_update"].toString();

                        QJsonObject location = value["location"].toObject();

                          country = location["country"].toString();
                          id = location["id"].toString();
                          name = location["name"].toString();
                          timezones = location["timezones"].toString();
                          timezone_offset = location["timezone_offset"].toString();

                        QJsonObject now = value["now"].toObject();
                          clouds = now["clouds"].toString();
                          code = now["code"].toString();
                          dew_point = now["dew_point"].toString();
                          feels_like = now["feels_like"].toString();
                          humidity = now["humidity"].toString();
                          pressure = now["pressure"].toString();
                          temperature = now["temperature"].toString();
                          text = now["text"].toString();
                          visibility = now["visibility"].toString();
                          wind_direction = now["wind_direction"].toString();
                          wind_direction_degree = now["wind_direction_degree"].toString();
                          wind_scale = now["wind_scale"].toString();
                          wind_speed = now["wind_speed"].toString();
/**
                          const char* fromQstr = country.toUtf8().constData();
                          QLabel *label = new QLabel();
                          label->setText(now["wind_speed"].toString());
                          label->show();


                        qDebug() << "last update:" << last_update << "country:" << country;
                        qDebug() << "id:" << id << "name:" << name;
                        qDebug() << "timezones:" << timezone << "timezone_offset:" << timezone_offset;
                        qDebug() << "clouds:" << clouds << "code:" << code;
                        qDebug() << "dew_point:" << dew_point << "feels_like:" << feels_like;

/**
                    }
                }

    } else {
        qDebug() << "Error:" << reply->errorString();
    }
    reply->deleteLater(); // 不再需要时删除reply对象
}
}
**/
